import { DELETE, GET, Params, POST, Result } from '@/plugins/axios';
import type { ArticleApiType } from './namespace';
import type { ResponseResult } from '@/types/response';

class articleApi {
  @POST('article/list')
  async list(@Params data: ArticleApiType.Request, @Result res?: ResponseResult<ArticleApiType.Article[]>) {
    const result = {
      list: res?.data ?? [],
      total: res?.meta?.total ?? 0,
    };
    return result;
  }

  @GET('article/detail')
  async detail(@Params _data: ArticleApiType.DetailRequest, @Result res?: ResponseResult<ArticleApiType.Article>) {
    return res?.data ?? {};
  }

  @GET('article/my-article')
  async myArticle(@Params _data: ArticleApiType.Request, @Result res?: ResponseResult<ArticleApiType.Article[]>) {
    const result = {
      list: res?.data ?? [],
      total: res?.meta?.total ?? 0,
    };
    return result;
  }

  @DELETE('article/delete')
  async delete(@Params _data: ArticleApiType.DeleteRequest) {}

  @POST('article/update-status')
  async changeStatus(@Params _data: ArticleApiType.UpdateStatusRequest) {}

  @POST('article/create')
  async create(@Params _data: ArticleApiType.CreateRequest, @Result res?: ResponseResult<{ id: string }>) {
    return { id: res?.data?.id };
  }

  @POST('article/update')
  async update(@Params _data: ArticleApiType.UpdateRequest) {}
}

export default new articleApi();
